package com.zhijiang.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2023-02-24 10:06:39
 */
public class TimeUtil {
    private static final String pattern = "yyyy-MM-dd HH:mm:ss";

    public static Date getNextYearPreDay() {
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
        ca.setTime(new Date());   //设置时间为当前时间
        ca.add(Calendar.YEAR, -1); //年份+1
        // ca.add(Calendar.MONTH, -1); // 月份-1
        ca.add(Calendar.DATE, -1); // 日期-1

        return ca.getTime();
    }

    public static String format(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }


    //public static void main(String[] args) {
    //    Date nextYearPreDay = TimeUtil.getNextYearPreDay();
    //    DateTime dateTime3 = DateUtil.beginOfYear(nextYearPreDay);
    //    DateTime dateTime4 = DateUtil.endOfYear(nextYearPreDay);
    //    String format = TimeUtil.format(dateTime3);
    //    String format1 = TimeUtil.format(dateTime4);
    //    System.out.println(format);
    //    System.out.println(format1);
    //
    //}

    public static String subtractDate() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        //new一个Calendar类 把Date放入进去
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.add(Calendar.DATE, -1);
        //转换成String类型
        String format = simpleDateFormat.format(instance.getTime());
        return format;
    }

    //public static String lastDateTime(Long day){
    //    String now = DateUtil.format(new Date(), "yyyyMMdd");
    //    Long time = Long.valueOf(now);
    //    Long lastTime = time-day;
    //    String s = String.valueOf(lastTime);
    //    return s;
    //}
    //
    //public static void main(String[] args) {
    //    String s = lastDateTime(7L);
    //    System.out.println(s);
    //}

    public static BaseQuery initBaseQuery(BaseQuery baseQuery) {
        Date parse = DateUtil.parse(baseQuery.getStartTime());
        DateTime dateTime = DateUtil.beginOfDay(parse);
        String s = DateUtil.formatDateTime(dateTime);
        baseQuery.setStartTime(s);
        DateTime parse1 = DateUtil.parse(baseQuery.getEndTime());
        DateTime dateTime1 = DateUtil.endOfDay(parse1);
        String s1 = DateUtil.formatDateTime(dateTime1);
        baseQuery.setEndTime(s1);
        return baseQuery;
    }


}
